package com.water.camera.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;

import com.water.camera.adapter.MarkListAdapter;
import com.water.camera.databinding.FragMarkListBinding;
import com.water.camera.it.WaterMarkChangeListener;

public class MarkListFragment extends BaseFragment implements WaterMarkChangeListener {
    int index;
    FragMarkListBinding binding;
    WaterMarkChangeListener listener;

    public void setIndex(int i, WaterMarkChangeListener listener) {
        index = i;
        this.listener = listener;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = FragMarkListBinding.inflate(inflater, container, false);
        binding.list.setVisibility(View.VISIBLE);
        binding.tv.setVisibility(View.INVISIBLE);
        binding.list.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        MarkListAdapter adapter = new MarkListAdapter(index, this);
        binding.list.setAdapter(adapter);
        if (adapter.getItemCount() == 0) {
            binding.tv.setVisibility(View.VISIBLE);
            binding.list.setVisibility(View.INVISIBLE);
            binding.tv.setText(index + "");
        }
        return binding.getRoot();
    }

    @Override
    public void onWaterMarkChange(String name) {
        listener.onWaterMarkChange(name);
    }
}
